package xyxy.ymh;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

public class YmhConditional implements Condition {

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        try {
            Map<String, Object> annotationAttributes = annotatedTypeMetadata.getAnnotationAttributes(YmhConditionalClass.class.getName());
            String value = (String)annotationAttributes.get("value");
            conditionContext.getClassLoader().loadClass(value);
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }

    }
}
